@include('admin::layouts.header')
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>数据表列表</legend>
    </fieldset>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
@include('admin::layouts.footer')
<script type="text/html" id="size">
    @{{d.size}}
</script>
<script type="text/html" id="topBtn">
	<blockquote class="layui-elem-quote">
        数据库中共有<i class="count"></i>张表，共计<i class="size"></i>
        <a href="javascript:void(0)" id="backUp" class="layui-btn layui-btn-small pull-right">备份</a>
    </blockquote>
</script>
<script type="text/html" id="barDemo">
    <a lay-event="table_detail" class="layui-btn layui-btn-xs">详情</a>
</script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        var tableIn = table.render({
			id: 'database',
            elem: '#list',
            url: "{{route('admin.data_base.data')}}",
            method:'get',
			toolbar: '#topBtn',
			title:'模块配置',
            cols: [[
                {checkbox:true,fixed: true},
                {field: 'Name', title: '数据表名', width: 300, fixed: true,sort: true},
                {field: 'Rows',align: 'center', title: '数据条数', width: 150,sort: true},
                {field: 'Data_length',align: 'center', title: '占用空间', width: 150,templet:'#size',sort: true},
                {field: 'Engine',align: 'center', title: '类型', width: 110},
                {field: 'Collation',align: 'center', title: '排序规则', width: 200},
                {field: 'Comment',align: 'center', title: '备注', width: 200},
                {field: 'Create_time',align: 'center', title: '添加时间', width: 200,sort: true},
				{width:100, title: '操作',align:'center',align: 'center', toolbar: '#barDemo'} 
            ]],
			parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
				  return res;
			},
			done: function(res, curr, count){
                $('.count').html(res.tableNum);
                $('.size').html(res.total);
            }	
        });
		table.on('tool(list)', function(obj){
            var data = obj.data;
			if(obj.event === 'table_detail'){
				layer.open({
					type: 2,
					title: '新增',
					shade: [0.5],
					area: ['90%', '90%'],
					anim: 2,
					shift:2,
					maxmin: true, //开启最大化最小化按钮
					content: ["/admin/data_base/table_detail?comment="+data.Comment+"&table="+data.Name]
				});
			}
        });
		$('#backUp').click(function(){
            var obj = $(this);
            var checkStatus = table.checkStatus('database'); //test即为参数id设定的值
            var a = [];
            $(checkStatus.data).each(function(i,o){
                a.push(o.Name);
            });
            obj.addClass('layui-btn-disabled');
            obj.html('备份进行中...');
            $.post("{{route('admin.data_base.backup')}}",{tables:a},function(res){
				if (res.status == 1) {
						obj.removeClass('layui-btn-disabled');
						obj.html('备份');
						layer.msg(res.msg,{time:1000,icon:1});
				}else{
				   layer.msg(res.error,{time:1000,icon:2},function(){
						location.href = res.url;
						});
					return false;
				}	
            });
        })
    });
</script>
</body>
</html>